package cn.cctvcc.system.api.factory;

import cn.cctvcc.core.domain.R;
import cn.cctvcc.system.api.RemoteSysEmailService;
import cn.cctvcc.system.api.domain.SysEmail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @description: sysEmail feign降级
 * @author: Jiang
 * @create: 2021-09-23 17:47
 */
@Component
public class RemoteSysEmailFallbackFactory implements FallbackFactory<RemoteSysEmailService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSysEmailFallbackFactory.class);

    @Override
    public RemoteSysEmailService create(Throwable throwable) {
        log.error("邮件服务调用失败:{}", throwable.getMessage());
        return new RemoteSysEmailService() {

            @Override
            public R<?> add(SysEmail sysEmail) {
                return R.fail("邮件服务新增失败，请稍候再试");
            }
        };
    }
}
